/* GUI CONVERTED from ardrmtb.p (converter v1.76) Thu May 15 20:40:07 2003 */
/* ardrmtb.p - AR DR/CR MEMO MAINTENANCE Tax Calc. and Line Distribution*/
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                     */
/* All rights reserved worldwide.  This is an unpublished work.            */
/* $Revision: 1.9.1.11 $                                                         */
/*V8:ConvertMode=Maintenance                                               */
/* REVISION: 7.4       CREATED       : 07/13/93              BY: wep *H021**/
/*                     LAST MODIFIED : 06/23/94              BY: wep *H409**/
/*                                     09/08/94              BY: bcm *H509**/
/*                                     12/02/94              BY: bcm *H606**/
/* REVISION: 8.5       LAST MODIFIED : 01/08/96              BY: taf *J053**/
/*                                     07/23/96              by: mwd *J0VY**/
/* REVISION: 8.6       LAST MODIFIED : 11/25/96              BY: jzw *K01X**/
/*                                     12/30/96  BY: *K03F* Jeff Wootton   */
/* REVISION: 8.6       LAST MODIFIED : 10/09/97  BY: *K0JV* Surendra Kumar */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan        */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton      */
/* REVISION: 9.1      LAST MODIFIED: 10/22/99   BY: *N04P* Robert Jensen     */
/* REVISION: 9.1      LAST MODIFIED: 02/24/00   BY: *M0K0* Ranjit Jain       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.9.1.8     BY: Vihang Talwalkar   DATE: 10/22/01  ECO: *P01V*  */
/* Revision: 1.9.1.9     BY: Vinod Nair         DATE: 10/28/02  ECO: *N1W4*  */
/* Revision: 1.9.1.10    BY: Piotr Witkowicz    DATE: 03/14/03  ECO: *P0NP*  */
/* $Revision: 1.9.1.11 $    BY: Orawan S.          DATE: 05/08/03  ECO: *P0RJ* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* THIS LOGIC CONTROLS THE EDITING AND CALCULATION/RECALCULATION OF TAXES
   FOR THE ARD_DET RECORDS. THIS PROGRAM PROCESS FOR THE NEW TAX MANAGEMENT
   ONLY.
*/

/* DISPLAY TITLE */
{mfdeclre.i}
{cxcustom.i "ARDRMTB.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE ardrmtb_p_1 "View/Edit Tax Detail"
/* MaxLen: Comment: */

&SCOPED-DEFINE ardrmtb_p_2 "Recalculate Tax"
/* MaxLen: Comment: */

&SCOPED-DEFINE ardrmtb_p_3 " Tax Distribution "
/* MaxLen: Comment: */

&SCOPED-DEFINE ardrmtb_p_4 "Control"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define input-output parameter l_txcalc like mfc_logical.

/* HANDLE TO PROCESSING-LOGIC SUBPROGRAM ARDRMTPL.P */
define shared variable h_rules as handle no-undo.

define new shared variable undo_txdist like mfc_logical.

/* l_txchg IS SET TO TRUE IN TXEDIT.P WHEN TAXES ARE BEING EDITED  */
/* AND NOT JUST VIEWED IN DR/CR MEMO MAINTENANCE                   */
define new shared variable l_txchg     like mfc_logical initial no.

/* DEFINE RNDMTHD FOR CALL TO ARDRMTC.P */
define shared variable rndmthd      like rnd_rnd_mthd.
define shared variable base_det_amt like glt_amt.
define shared variable base_amt     like ap_amt.
define shared variable curr_amt     like glt_curr_amt.
define shared variable artotal      like ar_amt label {&ardrmtb_p_4}.
define shared variable ar_recno     as recid.
define shared variable ba_recno     as recid.
define shared variable ard_recno    as recid.
define shared variable undo_all     like mfc_logical.
define shared variable jrnl         like glt_ref.
define shared variable recalc_tax   like mfc_logical initial true.

define new shared variable ard_amt_fmt   as character.
define variable tax_tr_type   like tx2d_tr_type.
define variable tax_nbr       like tx2d_nbr.
define variable tax_lines     like tx2d_line initial 0.
define variable tax_env       like txed_tax_env.

define variable tax_total     like tx2d_totamt.
define variable tax_edit      like mfc_logical initial false.
define variable recalc_frame  like mfc_logical initial false.
define variable edit_frame    like mfc_logical initial false.
define variable undo_edittx   like mfc_logical initial false.
define variable undo_recalctx like mfc_logical initial false.
define variable undo_msgloop  like mfc_logical initial false.
define variable recalc_flg    like mfc_logical initial false.
define variable edit_flg      like mfc_logical initial false.

{&ARDRMTB-P-TAG2}
{txcalvar.i}

define new shared frame tax_dist.

{&ARDRMTB-P-TAG1}

{txcurvar.i "NEW"}

/* DEFINE LOGISTICS TABLES */
{lgardefs.i &type="lg"}

/* DEFINE SHARED FRAME B */
{ardrfmb.i}

/* DEFINE FORM TO CAPTURE EDIT AND RECALC FLAGS, */
/* USED ONLY WHEN UPDATING EXISTING VOUCHERS     */
FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
recalc_tax     colon 22 label {&ardrmtb_p_2}
   tax_edit       colon 22 label {&ardrmtb_p_1}
 SKIP(.4)  /*GUI*/
with frame recalc_tax row 10 overlay centered
                             side-labels attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-recalc_tax-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame recalc_tax = F-recalc_tax-title.
 RECT-FRAME-LABEL:HIDDEN in frame recalc_tax = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame recalc_tax =
  FRAME recalc_tax:HEIGHT-PIXELS - RECT-FRAME:Y in frame recalc_tax - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME recalc_tax = FRAME recalc_tax:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame recalc_tax:handle).

/* DEFINE FORM TO DISPLAY TAX DISTRIBUTION */
FORM /*GUI*/ 
   ard_acct
   ard_sub
   ard_cc
   ard_entity
   ard_project
   ard_desc
      format "x(15)"
   ard_amt
with frame tax_dist
   13 down width 80
   title color normal (getFrameTitle("TAX_DISTRIBUTION",24)) THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame tax_dist:handle).

ard_amt_fmt = ard_amt:format in frame tax_dist.
{gprun.i ""gpcurfmt.p"" "(input-output ard_amt_fmt,
                          input        rndmthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.

ard_amt:format in frame tax_dist = ard_amt_fmt.

find ba_mstr where recid(ba_mstr) = ba_recno exclusive-lock no-error.
find ar_mstr where recid(ar_mstr) = ar_recno exclusive-lock no-error.
find first gl_ctrl no-lock.
find first arc_ctrl no-lock.

/* LOOP TO PERFORM NEW TAX MANAGEMENT EVENTS ON DETAIL
LINE ITEMS.  TWO FLAGS ARE USED TO CONTROL THE FOLLOWING
POP-UP WINDOWS THAT ARE USED TO DETERMINE THE PROCESSING
IF A NEW MEMO IS BEING ADDED, THE USER HAS THE
OPPORTUNITY OF VIEWING THE TAX DETAIL; TAX LINES WILL
AUTOMATICALLY BE CALCULATED.  IF THE EXISTING MEMO IS
BEING UPDATED, THE USER HAS THE OPPORTUNITY OF RECALC-
ULATING TAXES AND TO VIEW THE TAX DETAIL.

CHECK FOR EXISTING TAX LINES IN ARD_DET.  IF NO RECORDS
ARE FOUND, THIS MEANS IT IS A NEW DR/CR MEMO.  OTHERWISE,
THE EXISTING MEMO IS BEING UPDATED.                  */

find first ard_det
   where ard_nbr = ar_nbr
   and ard_tax = "t"
no-lock no-error.
if available ard_det
then
   recalc_flg = true.
else
   edit_flg = true.

/* INITIALIZE TAX FIELDS FOR CALLING TAX PROGRAMS */
assign
   tax_tr_type = "18"   /* 18 = DR/CR MEMO */
   tax_nbr = "".        /* HOW TO USE???   */

/* BEGIN LOOP */
txeditcalc:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   /* IF UPDATING A DR/CR MEMO - TAX DETAIL RECORDS EXIST */
   /* THIS POP-UP IS ONLY PERFORMED THE FIRST TIME        */
   if recalc_flg
   then do:
      /*DISPLAY POP-UP TO OBTAIN RECALC OR VIEW/EDIT TAX INFO*/
      undo_recalctx = true.

      {&ARDRMTB-P-TAG3}
      recalc:
      do on endkey undo, leave recalc:
         update recalc_tax tax_edit with frame recalc_tax.
         undo_recalctx = false.
      end.
      hide frame recalc_tax no-pause.
      if undo_recalctx
      then
         return.

      /* WHEN RECALCULATE TAXES IS SET TO YES SET l_txchg = TRUE */
      if recalc_tax
      then
         l_txchg = yes.

      {&ARDRMTB-P-TAG4}
      /*IF THE COMBINATION OF RECALC = "YES" AND VIEW/EDIT = "NO*/
      /*SET EDIT_FLG SO MESSAGE WILL BE DISPLAYED AFTER RECALC  */
      if recalc_tax
         and not tax_edit
      then
         edit_flg = true.

      recalc_flg = false.
   end.

   /* RECALULATE TAXES.  THIS IS DONE FOR "NEW VOUCHERS" AND */
   /* FOR EXISTING VOUCHERS IF THE RECALC_TAX FLAG IS TRUE   */
   if recalc_tax
   then do:
      /* DELETE THE OLD TAX ARD_DET LINES */
      {ardeltx.i &looplabel = deltax}

      /* CHECK PREVIOUS DETAIL FOR EDITED VALUES */
      find first tx2d_det
         where tx2d_ref     = ar_nbr
         and   tx2d_nbr     = tax_nbr
         and   tx2d_tr_type = tax_tr_type
         and   tx2d_edited
         no-lock no-error.
      if available(tx2d_det)
      then do:
         {pxmsg.i &MSGNUM=917 &ERRORLEVEL=2
                  &CONFIRM=recalc_tax &CONFIRM-TYPE='LOGICAL'}
      end.

      if recalc_tax
      then do:

         /* SET l_txcalc = YES AND PASS IT BACK TO  */
         /* ardrmta.p WHEN RE-CALCULATE TAXES = YES */
         l_txcalc = yes.

         /* NOTE nbr FIELD BLANK UNTIL I KNOW HOW TO USE IT */

         /* ADDED TWO PARAMETERS TO TXCALC.P, INPUT PARAMETER VQ-POST
            AND OUTPUT PARAMETER RESULT-STATUS. THE POST FLAG IS SET
            TO 'NO' BECAUSE WE ARE NOT CREATING QUANTUM REGISTER
            RECORDS FROM THIS CALL TO TXCALC.P */

         {gprun.i ""txcalc.p""  "(input  tax_tr_type,
                                  input  ar_nbr,
                                  input  tax_nbr,
                                  input  tax_lines,  /*ALL LINES*/
                                  input  no,         /* NO POSTING */
                                  output result-status)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      {&ARDRMTB-P-TAG5}
      /*DON'T DISPLAY TAX DISTRIBUTION SCREEN IF THE TAX EDIT IS */
      /*GOING TO BE DISPLAYED FIRST                              */
      if not tax_edit
      then do:
         hide frame b.
         clear frame tax_dist all no-pause.
         {gprun.i ""ardrmtc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         pause 0.
      end.
      recalc_tax = false.
   end.

   if lgData
   then
      return.

   /* IF NEW VOUCHER, OR IF VIEW/EDIT MESSAGE FLAG IS SET*/
   /* DISPLAY MESSAGE TO ALLOW FOR TAX LINE VIEW/EDIT    */
   if edit_flg
   then do:
      undo_msgloop = true.
      msgloop:
      do on endkey undo, leave msgloop:
         {pxmsg.i &MSGNUM=932 &ERRORLEVEL=1
                  &CONFIRM=tax_edit &CONFIRM-TYPE='LOGICAL'}
         /* VIEW/EDIT TAX DETAIL */
         undo_msgloop = false.
      end.

      {&ARDRMTB-P-TAG6}
      if undo_msgloop
      then
         return.
   end.

   /* TRY AND GET OUT - IF BOTH FLAGS ARE SET TO FALSE*/
   if not recalc_tax
      and not tax_edit
   then
      return.

   /* DISPLAY TAX EDIT DETAIL WINDOW */
   if tax_edit
   then do:
      {gprun.i ""txedit.p""  "(input  tax_tr_type,
                               input  ar_nbr,
                               input  tax_nbr,
                               input  tax_lines, /* ALL LINES     */
                               input  ar_tax_env,
                               output tax_total)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            
      {&ARDRMTB-P-TAG7}
      /* WHEN TAXES ARE EDITED AND JUST VIEWED IN TXEDIT.P       */
      /* OR WHEN RECALCULATE TAXES = YES THEN SET l_txchg = TRUE */
      if l_txchg
      then do:

         /* CALCULATE TOTALS */
         {gprun.i ""txtotal.p"" "(input  tax_tr_type,
                                  input  ar_nbr,
                                  input  tax_nbr,
                                  input  tax_lines, /* ALL LINES */
                                  output tax_total)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* CREATE DR/CR MEMO TAX DITRIBUTION RECORDS,  */
         /* DISPLAY TAX DISTRIBUTION FORM               */
         /* FIRST, DELETE THE OLD TAX MEMO LINES        */
         {ardeltx.i &looplabel = taxdel}

         clear frame tax_dist all no-pause.
         {gprun.i ""ardrmtc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         pause 0.

         assign
            l_txchg  = no
            tax_edit = false.
      end. /* IF l_txchg */
   end.

   assign
      l_txchg    = no
      recalc_flg = false
      edit_flg   = true.
end.
/*GUI*/ if global-beam-me-up then undo, leave.

